Spreadsheet

Use this very simple JavaScript spreadsheet to help with your sums. Enter numbers in the middle cells and they will be summed to the sides and bottoms of the sheet. After you type in each cell, press the tab key or click in another cell to activate the "changed" property. Be patient! It may take a second to load.

Discussion

This spreadsheet highlights JavaScript's flexibility. JavaScript itself generates the spreadsheet from the two variables sheetHeight and sheetWidth. The entire creation function is shown below. Border cells are marked with the string "text" to indicate they are not included in calculations. OnChange events trigger recalculation.
// Create the Spreadsheet
function startSheet()
{
    document.write("<FORM><TABLE>")
    for (var j = 0; j < sheetHeight; j++)
    {
        document.write("<TR>")
        for (var i = 0; i < sheetWidth; i++)
        {
            document.write("<TD ALIGN=CENTER>")
            document.write("<INPUT TYPE='TEXT' SIZE=6 "+
                " NAME = 'CELL"+i+"X"+j+"' ")                
            if ((i == 0) || (j == 0)) document.write(" VALUE='Text' ")
            else document.write(" VALUE='0' ")
            document.write(" onChange='recalculate()'>")
        }
        document.write("</TR>")
    }
    document.write("</TABLE></FORM>")
}
Copyright ©1998 by Charles River Media, All Rights Reserved